using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace Raptor.Client
{
  public partial class frmPreview : Form
  {
    #region Class Variables & Properties

    #region Variables
    private frmMain m_ReturnForm;

    private Dictionary<string, List<List<List<String>>>> m_SelectionObjects = new Dictionary<string,List<List<List<string>>>>();
    #endregion

    #region Properties
    public frmMain returnForm
    {
      get { return m_ReturnForm; }
      set { m_ReturnForm = value; }
    }

    public Dictionary<string, List<List<List<String>>>> SelectionObjects
    {
      get { return m_SelectionObjects; }
      set { m_SelectionObjects = value; }
    }
    #endregion

    #endregion

    #region Class Contructor
    public frmPreview()
    {
      InitializeComponent();
    }
    #endregion

    #region Class Events
    private void frmPreview_Load(object sender, EventArgs e)
    {
      foreach (KeyValuePair<string, List<List<List<string>>>> table in this.SelectionObjects)
      {
        TreeNode TableNode = trvPreview.Nodes.Add(table.Key.ToString());
        TreeNode FieldNode = TableNode.Nodes.Add("DO Fields");
        TreeNode DONode = TableNode.Nodes.Add("DO Options");
        TreeNode SearchNode = TableNode.Nodes.Add("Search Parameters");
        TreeNode SearchResultNode = TableNode.Nodes.Add("Search Results");
        TreeNode EmbeddedNode = TableNode.Nodes.Add("Embedded Objects");
        List<List<string>> doOption = table.Value[0];
        List<List<string>> embedOption = table.Value[1];
        List<List<string>> searchOption = table.Value[2];
        List<List<string>> searchResult = table.Value[3];

        for (int iDOIdx = 0; iDOIdx < doOption[0].Count; iDOIdx++)
        {
          DONode.Nodes.Add(doOption[0][iDOIdx]);
        }

        for (int iSearchIdx = 0; iSearchIdx < searchOption.Count; iSearchIdx++)
        {
          string sOptional = "";

          if (Convert.ToBoolean(searchOption[iSearchIdx][7]))
          {
            sOptional = "(Optional)";
          }

          TreeNode AddedNode = FieldNode.Nodes.Add(searchOption[iSearchIdx][0] + " (" + searchOption[iSearchIdx][1].ToString() + ")" + sOptional + (bool.Parse(searchOption[iSearchIdx][8].ToString()) ? "(Retrieve All)" : "") + (bool.Parse(searchOption[iSearchIdx][9].ToString()) ? "(Dependant Object)" : ""));

          if (Convert.ToBoolean(searchOption[iSearchIdx][5]))
          {
            AddedNode = SearchNode.Nodes.Add(searchOption[iSearchIdx][0] + " (" + searchOption[iSearchIdx][1].ToString() + ")" + sOptional);
          }
        }
        for (int iSearchResultIdx = 0; iSearchResultIdx < searchResult.Count; iSearchResultIdx++)
        {
          TreeNode AddedNode = SearchResultNode.Nodes.Add(searchResult[iSearchResultIdx][0]);// + " (" + searchOption[iSearchIdx][1].ToString() + ")");
        }
        if (embedOption != null)
        {
          for (int iEmbedIdx = 0; iEmbedIdx < embedOption.Count; iEmbedIdx++)
          {
            if (bool.Parse(embedOption[iEmbedIdx][4].ToString()) || bool.Parse(embedOption[iEmbedIdx][5].ToString()))
            {
              TreeNode AddedNode = EmbeddedNode.Nodes.Add(embedOption[iEmbedIdx][2] + " (" + embedOption[iEmbedIdx][0] + "." + embedOption[iEmbedIdx][1] + ")");
              AddedNode.Nodes.Add(embedOption[iEmbedIdx][2] + "." + embedOption[iEmbedIdx][3]);
              if (bool.Parse(embedOption[iEmbedIdx][4].ToString()))
                AddedNode.Nodes.Add("Embed as Object");
              else if (bool.Parse(embedOption[iEmbedIdx][5].ToString()))
                AddedNode.Nodes.Add("Embed as List");
              else if (!bool.Parse(embedOption[iEmbedIdx][4].ToString()) && !bool.Parse(embedOption[iEmbedIdx][5].ToString()))
                AddedNode.Nodes.Add("Not Embed");
              if (bool.Parse(embedOption[iEmbedIdx][6].ToString()))
                AddedNode.Nodes.Add("In Active");
              else
                AddedNode.Nodes.Add("Active");
              //if (bool.Parse(embedOption[iEmbedIdx][7].ToString()))
              //  AddedNode.Nodes.Add("Embedded Parent Object");
            }
          }
        }

      }
    }

    private void btnApprove_Click(object sender, EventArgs e)
    {
      this.returnForm.Approved = true;
      this.Close();
    }

    private void btnDecline_Click(object sender, EventArgs e)
    {
      this.returnForm.Approved = false;
      this.Close();
    }

    #endregion

    #region Class Methods
    #endregion
  }
}